package fschmidt.util.java;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;


public abstract class FutureValue<V> {

	private final FastFuture<V> ft = new FastFuture<V>(new Callable<V>() {
		public V call() throws Exception {
			return compute();
		}
	});

	public V get() throws ComputationException {
		ft.run();
		try {
			return ft.get();
		} catch(InterruptedException e) {
			throw new ComputationException(e);
		} catch(ExecutionException e) {
			throw ComputationException.newInstance(e);
		}
	}

	protected abstract V compute() throws Exception;
}
